package com.spark.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class CookieHelper {

	/**
	 * 根据名字获取cookie的值.
	 * 
	 * @param request
	 * @param name cookie名字
	 * @return String
	 */
	public static String getCookieValue(HttpServletRequest request,String name){
		Cookie[] cookies = request.getCookies();
		if(cookies != null){
			for(Cookie cookie : cookies){
				String cookieName = cookie.getName();
				if(cookieName.equals(name)){
					return cookie.getValue();
				}
			}
		}
		return null;
	}

}
